﻿@model GrainManage.Web.Models.Trade.AddTradeModel
@ScriptHelper.Autocomplete()
@ScriptHelper.CssLink("Create.css")
<script type="text/javascript">
    $(document).ready(function () {
        var data = { pageIndex: 0, pageSize: 100 };
        BindAutoComplete("/Type/GetGrainType", "#Grain", data, true);
        BindAutoComplete("/Type/GetTradeType", "#TradeType", data, true);
        $("#Price").dblclick(function (event) {
            var grain = $("#Grain").val();
            var priceType = $("#TradeType").val();
            if (grain && priceType) {
                $.post("/Price/GetLatestPrice", { grain: grain, priceType: priceType }, function (data) {
                    $("#Price").val(data.UnitPrice);
                });
            }
        });
        $("#ActualMoney").dblclick(function (event) {
            var grain = $("#Grain").val();
            var priceType = $("#TradeType").val();
            var unitPrice = parseFloat($("#Price").val());
            var weight = parseFloat($("#Weight").val());
            if (grain && priceType && unitPrice > 0 && weight > 0) {
                $("#ActualMoney").val((unitPrice * weight).toFixed(2));
            }
        });
    });
</script>
@using (Html.BeginForm("Insert", "Trade", FormMethod.Post))
{
    <table class="create">
        <tr>
            <td>@Html.LabelFor(model => model.ContactID)</td>
            <td>@Html.EditorFor(model => model.ContactID)</td>
            <td>@Html.ValidationMessageFor(model => model.ContactID)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.TradeType)</td>
            <td>@Html.EditorFor(model => model.TradeType)</td>
            <td>@Html.ValidationMessageFor(model => model.TradeType)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.Grain)</td>
            <td>@Html.EditorFor(model => model.Grain)</td>
            <td>@Html.ValidationMessageFor(model => model.Grain)</td>
        </tr>

        <tr>
            <td>@Html.LabelFor(model => model.Price)</td>
            <td>@Html.EditorFor(model => model.Price)</td>
            <td>@Html.ValidationMessageFor(model => model.Price)</td>
        </tr>

        <tr>
            <td>@Html.LabelFor(model => model.Weight)</td>
            <td>@Html.EditorFor(model => model.Weight)</td>
            <td>@Html.ValidationMessageFor(model => model.Weight)</td>
        </tr>

        <tr>
            <td>@Html.LabelFor(model => model.ActualMoney)</td>
            <td>@Html.EditorFor(model => model.ActualMoney)</td>
            <td>@Html.ValidationMessageFor(model => model.ActualMoney)</td>
        </tr>

        <tr>
            <td>@Html.LabelFor(model => model.Remarks)</td>
            <td>@Html.EditorFor(model => model.Remarks)</td>
            <td>@Html.ValidationMessageFor(model => model.Remarks)</td>
        </tr>

        <tr class="submit">
            <td></td>
            <td>
                <input type="submit" value="@GrainManage.Web.Resources.GlobalResx.Create" />
            </td>
        </tr>
    </table>
}
